var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = cc._decorator,
    s = r.ccclass,
    c = r.property,
    p = (r.menu, r.executeInEditMode),
    l = (function (t) {
        i(e, t);
        function e() {
            var e = (null !== t && t.apply(this, arguments)) || this;
            e.lvIndex = 0;
            e.startCount = 18;
            e.tipLab = null;
            e.parseNode = null;
            e.unUseNode = null;
            e.saveMap = null;
            e.tempJson = {};
            e.viewTipIndex = 0;
            e._saveData = !1;
            return e;
        }
        Object.defineProperty(e.prototype, "saveData", {
            get: function () {
                return !1;
            },
            set: function () {
                console.log("EditorCom ----------------- 11111");
                this.unUseNode.active = !1;
                this.save();
                this.viewTipIndex++;
                this.tipLab.string = "存储成功" + this.lvIndex;
            },
            enumerable: !1,
            configurable: !0
        });
        Object.defineProperty(e.prototype, "updateView", {
            get: function () {
                return !1;
            },
            set: function () {
                this.parseMakeNode();
                this.tipLab.string = "更新目录成功当前关卡:" + this.lvIndex;
                this.getSaveData();
                var t = Editor.Project.path + "//Res/map/map001.json",
                    e = Editor.remote.assetdb.fspathToUrl(t);
                -1 !== e.indexOf("assets") && Editor.assetdb.refresh(e);
            },
            enumerable: !1,
            configurable: !0
        });
        Object.defineProperty(e.prototype, "nextLv", {
            get: function () {
                return !1;
            },
            set: function () {
                this.lvIndex++;
                this.updateView = !0;
            },
            enumerable: !1,
            configurable: !0
        });
        Object.defineProperty(e.prototype, "lastLv", {
            get: function () {
                return !1;
            },
            set: function () {
                this.lvIndex--;
                this.lvIndex = Math.max(0, this.lvIndex);
                this.updateView = !0;
            },
            enumerable: !1,
            configurable: !0
        });
        e.prototype.udpataMap = function () {};
        e.prototype.onLoad = function () {
            this.udpataMap();
        };
        e.prototype.getLvJosn = function () {
            return this.saveMap.json.data[this.lvIndex];
        };
        e.prototype.resetCopy = function () {
            if (this.saveMap) {
                var t = this.getLvJosn();
                console.log("EditorCom ----------------- 拷贝数据", t);
                this.startCount = (t && t.c) || 18;
                this.tempJson = {};
                for (var e in t) "c" != e && (this.tempJson[e] = t[e]);
            }
        };
        e.prototype.parseMakeNode = function () {
            this.startCount = 18;
            this.clearAllNode();
            this.resetCopy();
            console.log("EditorCom ----------------- 解析关卡数据", this.tempJson);
            for (var t in this.tempJson) this.addNode(this.tempJson[t]);
        };
        e.prototype.addNode = function (t) {
            var e = this.getNewNode();
            if (e) {
                e.parent = this.parseNode;
                e.setPosition(cc.v2(t.x, t.y));
                e.angle = t.r || 0;
            }
        };
        e.prototype.getNewNode = function () {
            return this.unUseNode.childrenCount > 1
                ? this.unUseNode.children[1]
                : 1 == this.unUseNode.childrenCount
                ? cc.instantiate(this.unUseNode.children[0])
                : null;
        };
        e.prototype.clearAllNode = function () {
            for (; this.parseNode.childrenCount > 0; ) this.parseNode.children[0].parent = this.unUseNode;
        };
        e.prototype.getParseData = function () {
            for (var t = {}, e = 0; e < this.parseNode.children.length; e++)
                t[e] = {
                    x: this.parseNode.children[e].x,
                    y: this.parseNode.children[e].y,
                    r: this.parseNode.children[e].angle || 0
                };
            return t;
        };
        e.prototype.getCopyData = function (t) {
            var e = {};
            for (var o in t) e[o] = t[o];
            return e;
        };
        e.prototype.getSaveData = function () {
            var t = {},
                e = this.saveMap.json;
            t.ver = e.ver;
            t.tip = e.tip;
            t.data = this.getCopyData(e.data);
            var o = this.getParseData();
            console.log("EditorCom ----------------- 地图数据", o);
            t.data[this.lvIndex] = o;
            t.data[this.lvIndex].c = this.startCount;
            this.saveMap.json = t;
            return t;
        };
        e.prototype.save = function () {
            var t = this.getSaveData();
            console.log("EditorCom ----------------- ", t);
            d.saveFileInAssets("/Res/map/", "map001.json", JSON.stringify(t));
        };
        e.prototype.init = function () {};
        n([c(cc.Integer)], e.prototype, "lvIndex", void 0);
        n([c({displayName: "初始卡牌数"})], e.prototype, "startCount", void 0);
        n([c(cc.Label)], e.prototype, "tipLab", void 0);
        n([c(cc.Node)], e.prototype, "parseNode", void 0);
        n([c(cc.Node)], e.prototype, "unUseNode", void 0);
        n([c(cc.JsonAsset)], e.prototype, "saveMap", void 0);
        n([c({displayName: "存储"})], e.prototype, "saveData", null);
        n([c({displayName: "刷新关卡数据"})], e.prototype, "updateView", null);
        n([c({displayName: "下一关"})], e.prototype, "nextLv", null);
        n([c({displayName: "上一关"})], e.prototype, "lastLv", null);
        return n([s, p], e);
    })(cc.Component);
o.default = l;
var d = (function () {
    function t() {}
    t.saveFile = function () {};
    t.saveFileInAssets = function (t, e, o) {
        this.saveFile("assets/" + t, e, o);
    };
    return t;
})();
